﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using Telerik.Web.UI;

namespace Sistema_de_Taller.SDT_UI.Replacement
{
    public partial class replacement_details : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public static String ReplacementID;

        private void Page_Init(object sender, System.EventArgs e)
        {
            ReplacementID = Request.QueryString["Id"];
            loadForm(ReplacementID);
        }

        private void loadForm(String ReplacementID)
        {
            DataSet Replacement;

            SDT_DAL.Utilities.Replacement_DAL ReplacementData = new SDT_DAL.Utilities.Replacement_DAL();

            Replacement = ReplacementData.ReplacementIdLoad(ReplacementID);

            //Cargo datos Repuestos
            txtID.Text = Replacement.Tables[0].Rows[0].ItemArray[0].ToString().Trim();
            txtName.Text = Replacement.Tables[0].Rows[0].ItemArray[1].ToString().Trim();
            txtBrand.Text = Replacement.Tables[0].Rows[0].ItemArray[2].ToString().Trim();
            txtStock.Text = Replacement.Tables[0].Rows[0].ItemArray[3].ToString().Trim();
            txtOutput.Text = Replacement.Tables[0].Rows[0].ItemArray[4].ToString().Trim();
            txtLocation.Text = Replacement.Tables[0].Rows[0].ItemArray[4].ToString().Trim();
        
        }

        protected void btnUpdateReplacement_Click(object sender, EventArgs e)
        {
            Common_Files.Definitions.Remplacement Remplacement = new Common_Files.Definitions.Remplacement();

            Remplacement.Replacement_ID = txtID.Text;
            Remplacement.Replacement_Name = txtName.Text;
            Remplacement.Replacement_Brand = txtBrand.Text;
            Remplacement.Replacement_Stock = Convert.ToUInt32(txtStock.Text);
            if (txtOutput.Text.Length == 0) txtOutput.Text = "0";
            Remplacement.Replacement_Output = Convert.ToUInt32(txtOutput.Text);
            Remplacement.Replacement_Location = txtLocation.Text;

            SDT_BS.Replacement_BS replacement_bs = new SDT_BS.Replacement_BS();

            lblMessages.Text = "Repuesto modificado satisfactoriamente";
            MessageOk.Visible = true;

            SDT_DAL.Utilities.Replacement_DAL modifico = new SDT_DAL.Utilities.Replacement_DAL();
            modifico.ReplacementChange(Remplacement);
        }
    }
}